#include<iostream>
#include<cstdio>
#include<set>
using namespace std;
const int maxn=2000001;
set<int>v;
bool c[maxn];
int main(){
    int n,x;
    while(scanf("%d%d",&n,&x)!=EOF){
          v.clear();
          int d;
          for(int i=0;i<n;i++){
              scanf("%d",&d);
              v.insert(d);  
              }
          for(int i=0;i<maxn&&i<x;i++)c[i]=0;    
          if(x==2){puts("0");continue;}
          if(n==0){puts("-1");continue;}
          if(v.count(1)>0){
             puts("1");
             continue;   
             }
          int sum=0;   
          for(int i=2;i<maxn&&i<x;i++){
              if(!c[i]){
                 if(v.count(i)>0){
                    sum++;
                    for(int j=i;j<maxn&&j<x;j+=i)c[j]=true;    
                    }
                 else {sum=-1;break;}      
                 }  
              }   
          cout<<sum<<endl;    
          }
    return 0;
    }
